home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / text / tex / mma2ltx121.lha / mma2ltx / mmatext.sty < prev    next >
Text File  |  1995-05-16  |  10KB  |  287 lines

  1. %
  2. % macros for picture produced by "mma2ltx"
  3. % version 1.21 - 16 May 1995
  4. %
  5. % Copyright (C) 1994, 1995 by Giuseppe Ghib\`o (<ghibo@galileo.polito.it>)
  6. %
  7. % ----------------------------------------------------------------------------
  8. %
  9. \typeout{Document Style `mmatext' - v1.21 (16/5/95) - (C) 1994,1995 by Giuseppe Ghibo`}
  10. %
  11. \gdef\mma@prologue{texmma22.pro}% Mathematica v2.2 PostScript prologue file.
  12. %
  13. %
  14. \newdimen\mma@tmpdima
  15. \newdimen\mma@tmpdimb
  16. \newdimen\mma@tmpdimc
  17. \newdimen\mma@tmpdimd
  18. \newbox\mma@tmpbox
  19. %
  20. %
  21. % \mmaheaderprotrue   = include the prologue file \mma@prologue (once) using
  22. %                       the \special{header=...}.
  23. % \mmaheaderprofalse  = don't include the prologue file \mma@prologue.
  24. % \mma@proloadedtrue  = the prologue \mma@prologue has been already loaded.
  25. % \mma@proloadedfalse = the prologue \mma@prologue has not been loaded.
  26. % \mma@whitebgtrue    = the object will have a white background
  27. % \mma@whitebgfalse   = the object will have a transparent background
  28. \newif\ifmmaheaderpro  \mmaheaderprotrue
  29. \newif\ifmma@proloaded \mma@proloadedfalse
  30. \newif\ifmma@whitebg
  31. %
  32. %
  33. % \@nameedef is similar to the LaTeX command \@namedef, except it uses \edef
  34. % instead of \def.
  35. \def\@nameedef#1{\expandafter\edef\csname #1\endcsname}
  36. %
  37. \let\ccd=\catcode
  38. \ccd`\p=12\ccd`\t=12
  39. \def\del@dim#1pt{#1}%
  40. \ccd`\p=11\ccd`\t=11
  41. %
  42. \def\pt@mm{0.3514598}\def\unit@mm{mm}%
  43. \def\pt@cm{0.03514598}\def\unit@cm{cm}%
  44. \def\pt@pt{1}\def\unit@pt{pt}%
  45. \def\pt@bp{0.99626401}\def\unit@bp{bp}%
  46. \def\pt@pc{0.08333333}\def\unit@pc{pc}%
  47. \def\pt@in{0.013837}\def\unit@in{in}%
  48. \def\pt@dd{0.9345719}\def\unit@dd{dd}%
  49. \def\pt@cc{0.07788099}\def\unit@cc{cc}%
  50. \def\pt@dbp{9.9626401}\def\unit@dbp{dbp}%
  51. %
  52. \def\deldim#1{\expandafter\del@dim\the#1}%trash the trailing 'pt'
  53. \def\dimtomac#1#2#3{%
  54. % \dimtomac (expands a dimension register into a macro)
  55. % #1 = a dimension register (e.g., \mydim, \dimen0, ...)
  56. % #2 = conversion factor from pt to a choosed unit or
  57. %      one of mm, cm, pt, bp, pc, in, dd, cc, sp, dbp.
  58. % #3 = macro to which assign the converted value.
  59. \lowercase{\edef\convfactor{#2}}
  60. \ifx\convfactor\unit@mm\def\convfactor{\pt@mm}\else
  61. \ifx\convfactor\unit@cm\def\convfactor{\pt@cm}\else
  62. \ifx\convfactor\unit@pt\def\convfactor{\pt@pt}\else
  63. \ifx\convfactor\unit@bp\def\convfactor{\pt@bp}\else
  64. \ifx\convfactor\unit@dbp\def\convfactor{\pt@dbp}\else
  65. \ifx\convfactor\unit@pc\def\convfactor{\pt@pc}\else
  66. \ifx\convfactor\unit@in\def\convfactor{\pt@in}\else
  67. \ifx\convfactor\unit@dd\def\convfactor{\pt@dd}\else
  68. \ifx\convfactor\unit@cc\def\convfactor{\pt@cc}\else
  69. \fi\fi\fi\fi\fi\fi\fi\fi\fi
  70. \mma@tmpdima=#1%
  71. \ifx\convfactor\unit@sp\@nameedef{#3}{\number\mma@tmpdima}\else
  72. \mma@tmpdimb=\convfactor\mma@tmpdima%
  73. \@nameedef{#3}{\deldim\mma@tmpdimb}\fi
  74. }% end of dimtomac definition
  75. %
  76. %
  77. \newdimen\mma@dimunit \mma@dimunit=1bp
  78. \newdimen\mma@llx \newdimen\mma@urx \newdimen\mma@width  \newdimen\mma@oldwd
  79. \newdimen\mma@lly \newdimen\mma@ury \newdimen\mma@height \newdimen\mma@oldht
  80. \newdimen\mma@x \newdimen\mma@y
  81. \newdimen\mma@deltax \newdimen\mma@deltay
  82. %
  83. \gdef\mma@wd{161}%  default width in bp
  84. \gdef\mma@ht{100}%  default height in bp
  85. \gdef\mma@unit{bp}% default unit = bp
  86. \mma@width=\mma@wd bp
  87. \mma@height=\mma@ht bp
  88. \mma@llx=\z@ \mma@urx=\mma@width
  89. \mma@lly=\z@ \mma@ury=\mma@height
  90. \mma@deltax=\z@ \mma@deltay=\z@
  91. %
  92. %
  93. % *************
  94. % *           *
  95. % * mmasetpic *
  96. % *           *
  97. % *************
  98. \def\mmasetpic(#1,#2){\@ifnextchar({\mma@oldsetpic(#1,#2)}{%
  99. \mma@setpic(#1,#2)}}
  100. %
  101. \def\mma@setpic(#1,#2)[#3]#4{%
  102. % #1 = width of Mathematica PostScript picture
  103. % #2 = height of Mathematica PostScript picture
  104. % #3 = unit of measure
  105. % #4 = PostScript filename
  106. \lowercase{\edef\mma@unit{#3}}
  107. \mma@dimunit=1\mma@unit
  108. \mma@llx=\z@ \mma@urx=#1\mma@dimunit
  109. \mma@lly=\z@ \mma@ury=#2\mma@dimunit
  110. \mma@width=#1\mma@dimunit \mma@height=#2\mma@dimunit
  111. \mma@oldwd=\mma@width \mma@oldht=\mma@height
  112. \dimtomac{\mma@oldwd}{bp}{mma@wd}
  113. \dimtomac{\mma@oldht}{bp}{mma@ht}
  114. \def\mma@psname{#4}
  115. %
  116. % include the prologue file \mma@prologue at most once.
  117. \ifmma@proloaded\else
  118. \ifmmaheaderpro\special{header=texmma22.pro}\global\mma@proloadedtrue\fi
  119. \fi
  120. }
  121. %
  122. %
  123. % ***************
  124. % *             *
  125. % * mmatextfits *
  126. % *             *
  127. % ***************
  128. \def\mmatextfits(#1,#2)(#3,#4){\@ifnextchar({\mma@textfits(#1,#2)(#3,#4)}{%
  129.         \mma@textfits(#1,#2)(#3,#4)(0,0)}}
  130. %
  131. \def\mma@textfits(#1,#2)(#3,#4)(#5,#6)#7{%
  132. % #1 = x coord.
  133. % #2 = y coord.
  134. % #3 = sdx (bounding box x offs., like the Mathematica command "Text")
  135. % #4 = sdx (bounding box y offs., like the Mathematica command "Text")
  136. % #5 = extra offset to the x coord.
  137. % #6 = extra offset to the y coord.
  138. % #7 = text to fit.
  139. \setbox\mma@tmpbox=\hbox{#7}
  140. %
  141. % tmpllx = x - 1/2*wd*(sdx+1)
  142. \mma@tmpdima=#1\mma@dimunit \advance\mma@tmpdima by #5\mma@dimunit
  143. \mma@tmpdimb=#3\wd\mma@tmpbox
  144. \advance\mma@tmpdimb by \wd\mma@tmpbox
  145. \divide\mma@tmpdimb by 2
  146. \advance\mma@tmpdima by -\mma@tmpdimb
  147. \ifdim\mma@tmpdima < \mma@llx \mma@llx=\mma@tmpdima\fi
  148. %
  149. % tmplly = y - 1/2*(ht+dp)*(sdy+1)
  150. \mma@tmpdima=#2\mma@dimunit \advance\mma@tmpdima by #6\mma@dimunit
  151. \mma@tmpdimb=\ht\mma@tmpbox
  152. \advance\mma@tmpdimb by \dp\mma@tmpbox
  153. \mma@tmpdimb=#4\mma@tmpdimb
  154. \advance\mma@tmpdimb by \ht\mma@tmpbox
  155. \advance\mma@tmpdimb by \dp\mma@tmpbox
  156. \divide\mma@tmpdimb by 2
  157. \advance\mma@tmpdima by -\mma@tmpdimb
  158. \ifdim\mma@tmpdima < \mma@lly \mma@lly=\mma@tmpdima\fi
  159. %
  160. % tmpurx = x - 1/2*wd*(sdx-1)
  161. \mma@tmpdima=#1\mma@dimunit \advance\mma@tmpdima by #5\mma@dimunit
  162. \mma@tmpdimb=#3\wd\mma@tmpbox
  163. \advance\mma@tmpdimb by -\wd\mma@tmpbox
  164. \divide\mma@tmpdimb by 2
  165. \advance\mma@tmpdima by -\mma@tmpdimb
  166. \ifdim\mma@tmpdima > \mma@urx \mma@urx=\mma@tmpdima\fi
  167. %
  168. % tmpury = y - 1/2*(ht+dp)*(sdy-1)
  169. \mma@tmpdima=#2\mma@dimunit \advance\mma@tmpdima by #6\mma@dimunit
  170. \mma@tmpdimb=\ht\mma@tmpbox
  171. \advance\mma@tmpdimb by \dp\mma@tmpbox
  172. \mma@tmpdimb=#4\mma@tmpdimb
  173. \advance\mma@tmpdimb by -\ht\mma@tmpbox
  174. \advance\mma@tmpdimb by -\dp\mma@tmpbox
  175. \divide\mma@tmpdimb by 2
  176. \advance\mma@tmpdima by -\mma@tmpdimb
  177. \ifdim\mma@tmpdima > \mma@ury \mma@ury=\mma@tmpdima\fi
  178. %
  179. % Recalculate new picture size
  180. \mma@width=\mma@urx \advance\mma@width by -\mma@llx
  181. \mma@height=\mma@ury \advance\mma@height by -\mma@lly
  182. \mma@deltax=\mma@width \advance\mma@deltax by -\mma@oldwd
  183. \mma@deltay=\mma@height \advance\mma@deltay by -\mma@oldht
  184. }% end of \mmatextfits definition
  185. %
  186. %
  187. % **************
  188. % *            *
  189. % * mmapicture *
  190. % *            *
  191. % **************
  192. \def\mmapicture{%
  193. \bgroup
  194. \unitlength=1sp% so we can use the command \number
  195. \dimtomac{\mma@width}{\mma@unit}{mma@truewd}
  196. \dimtomac{\mma@height}{\mma@unit}{mma@trueht}
  197. \dimtomac{\mma@deltax}{\mma@unit}{mma@dx}
  198. \dimtomac{\mma@deltay}{\mma@unit}{mma@dy}
  199. \typeout{Mathematica  picture:\space'\mma@psname'\space%
  200.      size=(\mma@truewd\space x\space\mma@trueht\space\mma@unit)}
  201. \ifdim\mma@deltax > 0pt
  202.    \typeout{Mathematica picture:\space'\mma@psname'\space%
  203.             deltax=\mma@dx\space\mma@unit}
  204. \fi
  205. \ifdim\mma@deltay > 0pt
  206.    \typeout{Mathematica picture:\space'\mma@psname'\space%
  207.             deltay=\mma@dy\space\mma@unit}
  208. \fi
  209. \@killglue
  210. \begin{picture}(\number\mma@width,\number\mma@height)(\number\mma@llx,\number\mma@lly)
  211. \put(0,0){\special{psfile=\mma@psname\space hsize=\mma@wd\space vsize=\mma@ht}}}
  212. %
  213. \def\endmmapicture{\end{picture}\egroup}
  214. %
  215. %
  216. % **************
  217. % *            *
  218. % * mmaputtext *
  219. % *            *
  220. % **************
  221. \def\mmaputtext{\@ifstar{\mma@whitebgtrue\mma@puttext}{\mma@whitebgfalse%
  222. \mma@puttext}}
  223.  
  224. \def\mma@puttext(#1,#2)(#3,#4){\@ifnextchar({\mma@@puttext(#1,#2)(#3,#4)}{%
  225.         \mma@@puttext(#1,#2)(#3,#4)(0,0)}}
  226. %
  227. \def\mma@@puttext(#1,#2)(#3,#4)(#5,#6)#7{%
  228. % #1 = x coord.
  229. % #2 = y coord.
  230. % #3 = sdx (bounding box x offs., like the command "Text" of Mathematica)
  231. % #4 = sdx (bounding box y offs., like the command "Text" of Mathematica)
  232. % #5 = offset to the x coord.
  233. % #6 = offset to the y coord.
  234. % #7 = text (or object) to put.
  235. %
  236. \setbox\mma@tmpbox=\hbox{#7}
  237. \mma@x=#1\mma@dimunit \advance\mma@x by #5\mma@dimunit
  238. \mma@y=#2\mma@dimunit \advance\mma@y by #6\mma@dimunit
  239. %
  240. % xp = x - 1/2 * wd * (sdx + 1)
  241. \mma@tmpdima=#3\wd\mma@tmpbox
  242. \advance\mma@tmpdima by \wd\mma@tmpbox
  243. \divide\mma@tmpdima by 2
  244. \advance\mma@x by -\mma@tmpdima
  245. %
  246. % yp = y - 1/2*(sdy*htot + ht - dp)
  247. \mma@tmpdima=\ht\mma@tmpbox
  248. \advance\mma@tmpdima by \dp\mma@tmpbox
  249. \mma@tmpdima=#4\mma@tmpdima
  250. \advance\mma@tmpdima by \ht\mma@tmpbox
  251. \advance\mma@tmpdima by -\dp\mma@tmpbox
  252. \divide\mma@tmpdima by 2
  253. \advance\mma@y by -\mma@tmpdima
  254. %
  255. \mma@tmpdimc=\dp\mma@tmpbox
  256. \ifmma@whitebg
  257. \mma@tmpdimc=\wd\mma@tmpbox
  258. \mma@tmpdimd=\ht\mma@tmpbox \advance\mma@tmpdimd by \dp\mma@tmpbox
  259. \dimtomac{\mma@tmpdimc}{bp}{mma@tmpwd}
  260. \dimtomac{\mma@tmpdimd}{bp}{mma@tmpht}
  261. \advance\mma@y by -\dp\mma@tmpbox% special{psfile=mmawhite.eps...} has zero depth
  262. \put(\number\mma@x,\number\mma@y){\makebox(0,0)[lb]{\special{psfile=mmawhite.eps\space hsize=\mma@tmpwd\space vsize=\mma@tmpht}}}
  263. \advance\mma@y by \dp\mma@tmpbox\fi
  264. \put(\number\mma@x,\number\mma@y){\makebox(0,0)[lb]{\box\mma@tmpbox}}
  265. }% end of \mma@puttext definition
  266. %
  267. %
  268. % For backward compatibility with mma2ltx v1.03
  269. \def\mmashowunit#1{\gdef\mma@unit{#1}\global\mma@dimunit=1bp}
  270. %
  271. % For backward compatibility with mma2ltx v1.03
  272. \def\mma@oldsetpic(#1,#2)(#3,#4,#5,#6)#7{%
  273. % #1 = width of Mathematica PostScript picture in bp
  274. % #2 = height of Mathematica PostScript picture in bp
  275. % #3,#4,#5,#6 = transformation matrix (never used).
  276. % #7 = PostScript filename
  277. %
  278. \mma@llx=\z@ \mma@urx=#1\mma@dimunit
  279. \mma@lly=\z@ \mma@ury=#2\mma@dimunit
  280. \mma@width=#1\mma@dimunit \mma@height=#2\mma@dimunit
  281. \mma@oldwd=\mma@width \mma@oldht=\mma@height
  282. \gdef\mma@wd{#1} \gdef\mma@ht{#2}
  283. \gdef\mma@psname{#7}
  284. \ifmma@proloaded\else\special{header=texmma22.pro}\global\mma@proloadedtrue\fi
  285. }% end of mmaoldsetpic definition
  286.